import addressRequest from '@/request/addressRequest'
import xml2js from '@/utils/xml2js'
import commonRequest from '@/request/commonRequest'

/**
 * 获取HIS省市区街道信息(addressCode)
 * @param {JSON} params
 */
function hisAddressInfo(request = {}) {
  const reqBody = addressRequest.hisAddressInfo(request)
  return new Promise(function(resolve, reject) {
    commonRequest.gatewayRequest(reqBody).then(res => {
      xml2js.xml2json(res).then((res) => {
        if (res.Response.resultCode === '0') {
          if (res.Response.ResultList) {
            resolve(res.Response.ResultList)
          } else {
            resolve([])
          }
        } else {
          reject(res.Response.resultDesc)
        }
      })
    }).catch(err => {
      reject(err)
    })
  })
}

export default {
  hisAddressInfo
}
